<template>
  <div>
    <div class="wrapper" >
      <div class="formdata">
        <van-cell-group>
          <van-field class="textinput" type="text" clearable v-model="formdata.username" placeholder="请输入联系人姓名" />
          <van-field class="textinput" type="number" clearable v-model="formdata.mobile" placeholder="请输入联系电话" />
          <van-field class="textinput" type="textarea" clearable v-model="formdata.remark" placeholder="请输入备注内容" />
        </van-cell-group>
      </div>
      <div class="m_button" @click="submit">
        <div class="c_button">
          提交预约
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mineApi } from '@/api'
export default {
  components: {
  },
  async created() {
  },
  data() {
    return {
      formdata: {
        username: '',
        mobile: '',
        remark: ''
      }
    }
  },
  methods: {
    async submit() {
      if (!this.formdata.username) {
        this.$toast('请输入联系人姓名')
        return
      }
      if (!this.formdata.mobile) {
        this.$toast('请输入联系电话')
        return
      }
      const res = await mineApi.addAppoint({
        houseId: this.$route.query.id,
        ...this.formdata
      }).catch(err => {
        console.log('err', err)
        this.$toast('服务器出错')
      })
      if (res.code !== 200) {
        return
      }
      this.$toast('预约成功')
      this.$router.back()
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/assets/css/mixin.scss";
@import 'src/assets/css/variables.scss';
  .wrapper {
    .formdata{
      padding: 20px;
      background-color: #fff;
    }
    .textinput{
      border-radius: 10px;
      margin: 20px 0;
      background-color: #f0f0f0;
    }
  }
</style>
